import Base from 'models/base';

export default class CircleZoneLog extends Base {
  constructor(spaceId) {
    super();

    this.spaceId = spaceId;
    this.content = '';
    this.replyUnionid = null;
    this.placeholder = '评论';
  }

  resetLogData(log = null, isClear = false) {
    let unionid = log ? log.unionid : null;
    if (isClear || this.replyUnionid !== unionid) {
      this.content = '';
      this.replyUnionid = unionid;

      if (unionid === null) {
        this.placeholder = '评论';
      } else {
        this.placeholder = `回复 ${log.name} 的评论`;
      }
    }
  }

  checkValid() {
    if (this.content.trim() === '') {
      return 'content';
    }
    return '';
  }

  getObject() {
    let postData = {
      spaceId: this.spaceId,
      reviewContent: this.content,
    };

    let replyUnionid = this.replyUnionid;
    if (replyUnionid !== null) {
      postData.respondentUnionid = replyUnionid;
    }

    return postData;
  }
}
